﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Tasker.Common;
using Tasker.Common.Web;
using Tasker.Composition;

namespace Tasker.WebUI
{
    sealed class HttpContextContainer : IContextContainer
    {
        private readonly HttpContextCollectionContainer<object> _list = new HttpContextCollectionContainer<object>();

        public object GetInstance(Type type)
        {
            if (HttpContext.Current == null)
                return null;

            return _list.FirstOrDefault(instanse => type.IsAssignableFrom(instanse.GetType()));
        }

        public void RegisterInstance(Type type, object o)
        {
            if (HttpContext.Current == null)
                return;

            _list.Add(o);
        }

        public IEnumerable<object> GetInstances()
        {
            return _list;
        }

    }
}
